﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CI;
using System.Data.SqlClient;
using System.Data;

namespace CI.Caja.DL
{
    public class DA_Cajero
    {
        DA_Utilitario objUtility = new DA_Utilitario();
        public BE_Cajero ObtenerCajero(BE_Cajero prmCajeroBE)
        {
            SqlConnection cnx = objUtility.getConnection();
            try
            {
                cnx.Open();
                SqlCommand cmd = new SqlCommand("SP_SEL_CAJERO", cnx);
                cmd.CommandType = CommandType.StoredProcedure;

                var _with1 = (cmd.Parameters);
                _with1.Add("@IdPersonal", SqlDbType.VarChar).Value = prmCajeroBE.IdCajero;


                BE_Cajero objCajeroBE = new BE_Cajero();
                SqlDataReader reader = default(SqlDataReader);

                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    objCajeroBE.IdCajero = reader.GetString(reader.GetOrdinal("IdPersonal"));
                    objCajeroBE.Nombre = reader.GetString(reader.GetOrdinal("Nombre"));
                    objCajeroBE.Nombres = reader.GetString(reader.GetOrdinal("Nombres"));
                    objCajeroBE.Codigo = reader.GetString(reader.GetOrdinal("Codigo"));
                    objCajeroBE.Apellido = reader.GetString(reader.GetOrdinal("Apellido"));
                }

                return objCajeroBE;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cnx.Close();
            }
        }


        
        public List<BE_Cajero> ObtenerCajeros()
        {
            SqlConnection cnx = objUtility.getConnection();
            try
            {
                cnx.Open();
                SqlCommand cmd = new SqlCommand("PR_SEL_CAJEROS", cnx);
                cmd.CommandType = CommandType.StoredProcedure;

                //var _with1 = (cmd.Parameters);
                //_with1.Add("@NroOrden", SqlDbType.VarChar).Value = prmOrdenBE.NroOrden;

                SqlDataReader reader = default(SqlDataReader);

                reader = cmd.ExecuteReader();

                List<BE_Cajero> objListadoCajeroBE = new List<BE_Cajero>();

                while (reader.Read())
                {
                    BE_Cajero objCajeroBE = new BE_Cajero();

                    objCajeroBE.IdCajero = reader.GetString(reader.GetOrdinal("IdPersonal"));
                    objCajeroBE.Nombre = reader.GetString(reader.GetOrdinal("Nombre"));
                    objCajeroBE.Nombres = reader.GetString(reader.GetOrdinal("Nombres"));
                    objCajeroBE.Codigo = reader.GetString(reader.GetOrdinal("Codigo"));
                    objCajeroBE.Apellido = reader.GetString(reader.GetOrdinal("Apellido"));

                    objListadoCajeroBE.Add(objCajeroBE);
                }

                return objListadoCajeroBE;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cnx.Close();
            }
        }
    }
}
